// Learn TypeScript:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/typescript.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

import UIMgr from '../manager/UIMgr';
import ViewMgr from '../manager/ViewMgr';
import PageBaseView from './PageBaseView';
import HintView from './HintView';
import PlayerModel from '../model/PlayerModel';
import TableMgr from '../manager/TableMgr';
import SceneMgr from '../manager/SceneMgr';

const { ccclass, property } = cc._decorator;

@ccclass
export default class RootView extends cc.Component {
  // LIFE-CYCLE CALLBACKS:

  // onLoad () {}

  @property(cc.Node)
  pageNode: cc.Node = null;

  @property(cc.Node)
  hintView: cc.Node = null;

  onLoad() {
    //cc.game.addPersistRootNode(UIMgr.ins.node);
  }

  start() {}

  public init() {
    UIMgr.ins = this;
    this.viewInit();
    this.loginGame();
    console.log('初始化');
  }

  private async loginGame() {
    //读表
    //await TableMgr.inst.loadTableRes();
    //开始游戏
    PlayerModel.ins.login();
  }

  private viewInit(): void {
    let pageScript: PageBaseView = this.pageNode.getComponent(PageBaseView);
    ViewMgr.ins.initView(this.pageNode, pageScript);
  }

  //提示
  public hint(data: any): void {
    this.hintView.getComponent(HintView).showSingleHint(data);
  }

  // update (dt) {}
}
